package com.zero.common;

import java.util.HashSet;
import java.util.Set;

/**
 * mysql字段映射枚举
 *
 * @author wuxi
 * @date 2020-07-28
 */
public enum MysqlTypeMapEnum {
    /**
     * mysql字段映射枚举
     */
    LONG("bigint", "java.lang.Long", "Long"),

    INT("int", "java.lang.Integer", "Integer"),

    String("varchar", "java.lang.String", "String"),

    DateTime("datetime", "java.time.LocalDateTime", "LocalDateTime"),

    TINYINT("tinyint", "java.lang.Integer", "Integer"),

    DECIMAL("decimal", "java.math.BigDecimal", "BigDecimal"),

    CHAR("char","java.lang.String","String"),

    DATE("date","java.time.LocalDateTime", "LocalDateTime"),
    ;

    public static Set<String> specialTypeMap;

    static {
        specialTypeMap = new HashSet<>();
        specialTypeMap.add(MysqlTypeMapEnum.DateTime.getJavaType());
        specialTypeMap.add(MysqlTypeMapEnum.DECIMAL.getJavaType());
    }

    MysqlTypeMapEnum(String mysqlType, String javaTypeClass, String javaType) {
        this.mysqlType = mysqlType;
        this.javaTypeClass = javaTypeClass;
        this.javaType = javaType;
    }

    public static MysqlTypeMapEnum getType(String type) {
        for (MysqlTypeMapEnum value : MysqlTypeMapEnum.values()) {
            if (type.equals(value.getMysqlType())) {
                return value;
            }
        }
        throw new RuntimeException("未知mysql字段类型：" + type);
    }

    private String mysqlType;

    private String javaType;

    private String javaTypeClass;

    public String getJavaTypeClass() {
        return javaTypeClass;
    }

    public String getMysqlType() {
        return mysqlType;
    }

    public String getJavaType() {
        return javaType;
    }
}